﻿namespace BM.Tools.WebControls.MForm.Controls.DefaultTemplates
{    
    using System.Web.UI;

    using BM.Tools.WebControls.MForm.Controls.ValueHandlers;
    using System.Web.UI.WebControls;

    /// <summary>
    /// An <see cref="ITemplate" /> that creates a <see cref="TextBoxValueHandler" /> in the container control.
    /// </summary>
    public class TextBoxValueHandlerTemplate : ITemplate
    {        
        private readonly bool isTextArea;

        /// <summary>
        /// Initializes a new instance of the <see cref="TextBoxValueHandlerTemplate"/> class. 
        /// </summary>
        public TextBoxValueHandlerTemplate()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TextBoxValueHandlerTemplate"/> class. 
        /// </summary>
        /// <param name="isTextArea">
        /// The is text area.
        /// </param>
        public TextBoxValueHandlerTemplate(bool isTextArea)
        {
            this.isTextArea = isTextArea;
        }

        /// <summary>
        /// Instantiates a <see cref="TextBoxValueHandler" /> in the container control.
        /// </summary>
        /// <param name="container">
        /// The container.
        /// </param>
        public void InstantiateIn(Control container)
        {
            var handler = new TextBoxValueHandler();            
            if (isTextArea)
            {
                handler.TextBox.TextMode = TextBoxMode.MultiLine;
                handler.TextBox.Rows = 3;
            }

            container.Controls.Add(handler);
        }
    }
}